package edu.tgc.web.controller.code;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.abyss.common.web.controller.easyui.EasyuiResultBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.tgc.custom.EasyuiPageForm;
import edu.tgc.custom.EasyuiSort;
import edu.tgc.entity.code.TbCodeXmState;
import edu.tgc.service.code.CodeService;

@Controller
@RequestMapping(value = "code/xmState")
public class XmStateController {
    @Autowired
    private CodeService service;

    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(Integer id) {
        this.service.deletexmStateById(id);
        return EasyuiResultBuilder.buildAjaxResult("项目类型删除成功");
    }

    @RequestMapping(value = "/page")
    @ResponseBody
    public Object getxmStateListPage(EasyuiPageForm pageForm, EasyuiSort sort) {
        PageRequest pageRequest = pageForm.buildPageRequest(sort.buildSort());
        Page<TbCodeXmState> page = this.service.getXmStatePage(pageRequest);
        return EasyuiResultBuilder.buildDataGridResult(page);
    }

    @RequestMapping(value = "/create")
    public String gotoCreate() {
        return "code/xmState/create";
    }

    @RequestMapping(value = "/update")
    public String gotoUpdate(Integer id, ModelMap map) {
        TbCodeXmState xmState = this.service.findxmStateById(id);
        map.put("model", xmState);
        return "code/xmState/create";
    }

    @RequestMapping(value = "/manage", method = RequestMethod.GET)
    public String gotoxmStateList() {
        return "code/xmState/manage";
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Object xmStateSave(TbCodeXmState xmState) {
        /*TbCodexmState xmState=new TbCodexmState();
        xmState.setName(name);
        xmState.setSort(sort);*/
        this.service.xmStateSave(xmState);
        return EasyuiResultBuilder.buildAjaxResult("项目类型增加成功");
    }
    
    @RequestMapping(value="/xmStateCombo")
    @ResponseBody
    public Object xmStateCombo(){
    	List<Map<String, Object>> list=service.xmStateCombo();
    	return list;
    	
    }
}
